package com.example.myapplication;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.R;

public class BasketballActivity extends AppCompatActivity implements View.OnClickListener {

    private final int scoreArray[] = {1, 2, 3};
    private int lastScore_a, score_a;
    private Button btna_1, btna_2, btna_3;
    private TextView test_score_a, test_score_b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basketball);
        inintView();
    }

    private void inintView() {

        btna_1 = findViewById(R.id.btna_1);
        btna_2 = findViewById(R.id.btna_2);
        btna_3 = findViewById(R.id.btna_3);


        test_score_a = findViewById(R.id.score_a);


        btna_1.setOnClickListener(this);
        btna_2.setOnClickListener(this);
        btna_3.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btna_1:
                scoreAdd(0, scoreArray[0]);

                break;
            case R.id.btna_2:
                scoreAdd(0, scoreArray[1]);

                break;
            case R.id.btna_3:
                scoreAdd(0, scoreArray[2]);

                break;
            default:
                break;
        }
    }


    private void cancel() {
        if (score_a != 0 && score_a - lastScore_a >= 0) {
            score_a -= lastScore_a;
        }
        ShowText();
    }


    private void scoreAdd(int Tage, int score) {
        //Tage:   0:a  1:b
        if (Tage == 0 || Tage == 1) {
            if (Tage == 0) {
                lastScore_a = score;
                score_a += lastScore_a;
            }
        }

        ShowText();
    }




    private void ShowText() {
        test_score_a.setText(Integer.toString(score_a));
    }
}


